import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;



public class ExOnFindProperties {
	
	public static void main(String[] args) throws Exception {
	
		File file = new File("C:\\RK\\Localdebugging");
		File[] fileArray = file.listFiles();
		List<String> list = new ArrayList<String>();
		List<String> list1 = new ArrayList<String>();
		for(int i=0; i<fileArray.length; i++){
			if(fileArray[i].getName().trim().equals("global.xml")){
				FileInputStream fis = new FileInputStream(fileArray[i]);
				Properties properties = new Properties();
				properties.loadFromXML(fis);
				Enumeration enumeration = properties.keys();
				while(enumeration.hasMoreElements()){
					String key = (String) enumeration.nextElement();
					list.add(key);
				}
			}
				if(fileArray[i].getName().trim().equals("cfr.san.job.xml")){
					Document doc = ExOnFindProperties.parseXml(fileArray[i].getPath());
					NodeList Nodes = doc.getElementsByTagName("value");
					for(int j=0; j<Nodes.getLength(); j++){
						list1.add(Nodes.toString());
					}
					
				}
				System.out.println(list.toString());
				System.out.println(list1.toString());
					
				
				
				
				
			}
			
		}
		
	
		
		
	
	public static Document parseXml(String xml) 
			throws Exception
	{
		try {
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			factory.setValidating(true);
			factory.setNamespaceAware(true);
			factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
			DocumentBuilder builder = factory.newDocumentBuilder();        
			builder.setEntityResolver(new MyEntityResolver());
			builder.setErrorHandler(new MyErrorHandler() );
			return builder.parse(new InputSource(xml));
			
		}    
		catch (ParserConfigurationException pce) {
			pce.printStackTrace();
			throw pce;
		} 
		catch (IOException io) {
			io.printStackTrace();
			throw io;
		}
		catch (SAXException se){
			se.printStackTrace();
			throw se;
		}
		catch (Exception e){
			e.printStackTrace();
			throw e;
		}
	}
}
	class MyEntityResolver implements EntityResolver {

		public InputSource resolveEntity(String publicId, String systemId)
				throws SAXException, IOException {
			if (systemId.contains("process")) {
		        return new InputSource(MyEntityResolver.class.getResourceAsStream("process.xsd"));
		    } else {
		        return null;
		    }
		}
		
	}

	class MyErrorHandler implements ErrorHandler
	{

		public void error(SAXParseException e) throws SAXException {
			throw e;
			
		}

		public void fatalError(SAXParseException e) throws SAXException {
			throw e;
			
		}

		public void warning(SAXParseException e) throws SAXException {
			System.out.println("WARNING: " + e.getMessage());
			
		}


}
